package com.gzkemays.demo.service;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author gzkemays
 * @date 2021/3/18 15:56
 */
@Service
public class RedisServiceImpl implements RedisService {
  @Resource RedisTemplate redisTemplate;
  public static final String SAVE_TOKEN_HASH_KEY = "security::demo::token";

  @Override
  public void saveTokenWithAppId(String appId, String token) {
    redisTemplate.opsForHash().put(SAVE_TOKEN_HASH_KEY, appId, token);
  }

  @Override
  public String getTokenWithAppId(String appId) {
    Object token = redisTemplate.opsForHash().get(SAVE_TOKEN_HASH_KEY, appId);
    if (Objects.nonNull(token)) return token.toString();
    return null;
  }
}
